/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ainlolcat.aincalc2;

import org.ainlolcat.ainscience.entity.Entity;

import java.util.*;

/**
 *
 * @author Администратор
 */
public class Cleks {
    Collection<String> command;
    Map<String,CustomLeksemmasHandler> outcom;

    public static Integer TYPE_INTEGER = 11;
    public static Integer TYPE_DOUBLE = 12;
    public static Integer TYPE_STRING = 13;

    Map<String,Object> constants;
    Map<String,Integer> constantTypes;

    Map<String,Object> outvarval;
    Map<String,Integer> outvartype;

    Entity entity;

    public Cleks(Entity entity){
        this.entity = entity;
        init();
    }

    private void init(){
        initCommands();
        initVariables();
    }

    private void initVariables(){
        constants = new HashMap<String,Object>();
        constantTypes = new HashMap<String,Integer>();

        outvarval = new HashMap<String,Object>();
        outvartype = new HashMap<String,Integer>();

        constants.put("pi", Math.PI);
        constantTypes.put("pi", TYPE_DOUBLE);
    }

    private void initCommands(){
        command = new HashSet<String>();
        outcom = new HashMap<String,CustomLeksemmasHandler>();

        command.add("val");
        command.add("abs");
        command.add("sqrt");
        command.add("min");
        command.add("max");
        command.add("round");
        command.add("pow");
        command.add("sin");
        command.add("cos");
        command.add("tan");
    }


    //************check commands:***********************
    public boolean isCommand(String input){
        if (command.contains(input)) return true;
            else return false;
    }

    public boolean isConstant(String input){
        return constants.containsKey(input);
    }

    public boolean isVariable(String name){
        return (outvarval.get(name)!=null);
    }

    public boolean isOutCom(String name){
        return outcom.containsKey(name);
    }
    //**************************************************


    public Object getConstValue(String input){
        return constants.get(input);
    }

    public Integer getConstType(String input){
        return (Integer) constantTypes.get(input);
    }

    public void setOutCommand(String name, CustomLeksemmasHandler handler){
        //replace inner command
        command.remove(name);
        handler.setCLeks(this);
        outcom.put(name,handler);
    }

    public CustomLeksemmasHandler getOutCommand(String name){
        return outcom.get(name);
    }


    public void addVar(String name, Object val, Integer type){
        outvarval.put(name, val);
        outvartype.put(name, type);
    }

    public void updVar(String name, Object val){
        outvarval.remove(name);
        outvarval.put(name, val);
    }

    public Object getVarValue(String name) {
        return outvarval.get(name);
    }

    public Integer getVarType(String name) {
        return outvartype.get(name);
    }

}
